 package tools.packet;



import client.MapleCharacter;
import client.MapleClient;
import client.MapleEnumClass;
import client.inventory.Item;
import client.inventory.MapleInventoryType;
import client.inventory.MaplePet;
import constants.GameConstants;
import handling.opcode.NPCTalkOP;
import handling.opcode.SendPacketOpcode;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import server.life.MapleHideNpc;
import server.life.MapleNPC;
import server.life.PlayerNPC;
import server.shop.MapleShop;
import server.shop.MapleShopResponse;
import tools.HexTool;
import tools.data.output.MaplePacketLittleEndianWriter;

import java.awt.*;
import java.util.*;
import java.util.List;

































 public class NPCPacket
 {
   public static final int InitialQuizRes_Request = 0;
   public static final int InitialQuizRes_Fail = 1;
   public static final int TypeSpeedQuizNpc = 0;
   public static final int TypeSpeedQuizMob = 1;
   public static final int TypeSpeedQuizItem = 2;
   public static final int NoESC = 1;
   public static final int NpcReplacedByUser = 2;
   public static final int NpcReplayedByNpc = 4;
   public static final int FlipImage = 8;
/*  47 */   private static final Logger log = LogManager.getLogger(NPCPacket.class);

   public static byte[] sendNpcHide(List<MapleHideNpc> hide) {
/*  50 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/*  52 */     mplew.writeShort(SendPacketOpcode.NPC_HIDE.getValue());
/*  53 */     mplew.write(hide.size());
/*  54 */     for (MapleHideNpc h : hide) {
/*  55 */       mplew.writeInt(h.getNpcId());
     }
/*  57 */     return mplew.getPacket();
   }

   public static byte[] spawnNPC(MapleNPC life) {
/*  61 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/*  63 */     mplew.writeShort(SendPacketOpcode.SPAWN_NPC.getValue());
/*  64 */     mplew.writeInt(life.getObjectId());
/*  65 */     mplew.writeInt(life.getId());
/*  66 */     mplew.writeShort((life.getPosition()).x);
/*  67 */     mplew.writeShort(life.getCy());
/*  68 */     mplew.write(0);
/*  69 */     mplew.write((life.getF() == 1) ? 0 : 1);
/*  70 */     mplew.writeShort(life.getFh());
/*  71 */     mplew.writeShort(life.getRx0());
/*  72 */     mplew.writeShort(life.getRx1());
/*  73 */     mplew.write((life.isHidden() || GameConstants.isHideNpc(life.getMapid(), life.getId())) ? 0 : 1);
/*  74 */     mplew.writeInt(0);
/*  75 */     mplew.writeZeroBytes(5);
/*  76 */     mplew.writeInt(-1);
/*  77 */     mplew.writeZeroBytes(7);
/*  78 */     mplew.writeInt(0);
/*  79 */     mplew.write(0);

/*  81 */     return mplew.getPacket();
   }

   public static byte[] removeNPC(int objectid) {
/*  85 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/*  87 */     mplew.writeShort(SendPacketOpcode.REMOVE_NPC.getValue());
/*  88 */     mplew.writeInt(objectid);

/*  90 */     return mplew.getPacket();
   }

   public static byte[] removeNPCController(int objectid, boolean miniMap) {
/*  94 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/*  96 */     mplew.writeShort(SendPacketOpcode.SPAWN_NPC_REQUEST_CONTROLLER.getValue());
/*  97 */     mplew.writeBool(miniMap);
/*  98 */     mplew.writeInt(objectid);

/* 100 */     return mplew.getPacket();
   }

   public static byte[] spawnNPCRequestController(MapleNPC life, boolean MiniMap) {
/* 104 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 106 */     mplew.writeShort(SendPacketOpcode.SPAWN_NPC_REQUEST_CONTROLLER.getValue());
/* 107 */     mplew.write(1);
/* 108 */     mplew.writeInt(life.getObjectId());
/* 109 */     mplew.writeInt(life.getId());
/* 110 */     mplew.writeShort((life.getPosition()).x);
/* 111 */     mplew.writeShort(life.getCy());
/* 112 */     mplew.writeShort((life.getF() == 1) ? 0 : 1);
/* 113 */     mplew.writeShort(life.getFh());
/* 114 */     mplew.writeShort(life.getRx0());
/* 115 */     mplew.writeShort(life.getRx1());
/* 116 */     mplew.write(MiniMap ? 1 : 0);
/* 117 */     mplew.writeInt(0);
/* 118 */     mplew.writeZeroBytes(5);
/* 119 */     mplew.writeInt(-1);
/* 120 */     mplew.writeZeroBytes(7);
/* 121 */     mplew.writeInt(0);
/* 122 */     mplew.write(0);

/* 124 */     return mplew.getPacket();
   }

   public static byte[] spawnPlayerNPC(PlayerNPC npc) {
/* 128 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 129 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 131 */     mplew.writeShort(SendPacketOpcode.PLAYER_NPC.getValue());
/* 132 */     mplew.write((npc.getF() == 1) ? 0 : 1);
/* 133 */     mplew.writeInt(npc.getId());
/* 134 */     mplew.writeMapleAsciiString(npc.getName());
/* 135 */     mplew.write(npc.getGender());
/* 136 */     mplew.write(npc.getSkin());
/* 137 */     mplew.writeInt(npc.getFace());
/* 138 */     mplew.writeInt(0);
/* 139 */     mplew.write(0);
/* 140 */     mplew.writeInt(npc.getHair());
/* 141 */     Map<Byte, Integer> equip = npc.getEquips();
/* 142 */     Map<Byte, Integer> myEquip = new LinkedHashMap<>();
/* 143 */     Map<Byte, Integer> maskedEquip = new LinkedHashMap<>();
/* 144 */     for (Map.Entry<Byte, Integer> position : equip.entrySet()) {
/* 145 */       byte pos = (byte)(((Byte)position.getKey()).byteValue() * -1);
/* 146 */       if (pos < 100 && myEquip.get(Byte.valueOf(pos)) == null) {
/* 147 */         myEquip.put(Byte.valueOf(pos), position.getValue()); continue;
/* 148 */       }  if (pos > 100 && pos != 111) {
/* 149 */         pos = (byte)(pos - 100);
/* 150 */         if (myEquip.get(Byte.valueOf(pos)) != null) {
/* 151 */           maskedEquip.put(Byte.valueOf(pos), myEquip.get(Byte.valueOf(pos)));
         }
/* 153 */         myEquip.put(Byte.valueOf(pos), position.getValue()); continue;
/* 154 */       }  if (myEquip.get(Byte.valueOf(pos)) != null) {
/* 155 */         maskedEquip.put(Byte.valueOf(pos), position.getValue());
       }
     }
/* 158 */     for (Map.Entry<Byte, Integer> entry : myEquip.entrySet()) {
/* 159 */       mplew.write(((Byte)entry.getKey()).byteValue());
/* 160 */       mplew.writeInt(((Integer)entry.getValue()).intValue());
     }
/* 162 */     mplew.write(255);
/* 163 */     for (Map.Entry<Byte, Integer> entry : maskedEquip.entrySet()) {
/* 164 */       mplew.write(((Byte)entry.getKey()).byteValue());
/* 165 */       mplew.writeInt(((Integer)entry.getValue()).intValue());
     }
/* 167 */     mplew.write(255);
/* 168 */     mplew.write(255);
/* 169 */     Integer cWeapon = equip.get(Byte.valueOf((byte)-111));
/* 170 */     mplew.writeInt((cWeapon != null) ? cWeapon.intValue() : 0);
/* 171 */     Integer Weapon = equip.get(Byte.valueOf((byte)-111));
/* 172 */     mplew.writeInt((Weapon != null) ? Weapon.intValue() : 0);
/* 173 */     Integer subWeapon = equip.get(Byte.valueOf((byte)-10));
/* 174 */     mplew.writeInt((subWeapon != null) ? subWeapon.intValue() : 0);
/* 175 */     mplew.writeBool(false);
/* 176 */     for (int i = 0; i < 3; i++) {
/* 177 */       mplew.writeInt(npc.getPet(i));
     }
/* 179 */     mplew.writeZeroBytes(7);

/* 181 */     return mplew.getPacket();
   }

   public static byte[] getNPCTalk(int npc, byte msgType, String talk, String endBytes, byte type) {
/* 185 */     return getNPCTalk(npc, msgType, talk, endBytes, type, npc, false);
   }

   public static byte[] getNPCTalk(int npc, byte msgType, String talk, String endBytes, byte type, int diffNpc) {
/* 189 */     return getNPCTalk(npc, msgType, talk, endBytes, type, diffNpc, false);
   }

   public static byte[] getPlayerTalk(int npc, byte msgType, String talk, String endBytes, byte type) {
/* 193 */     return getNPCTalk(npc, msgType, talk, endBytes, type, npc, true);
   }

   public static byte[] getPlayerTalk(int npc, byte msgType, String talk, String endBytes, byte type, int diffNpc) {
/* 197 */     return getNPCTalk(npc, msgType, talk, endBytes, type, diffNpc, true);
   }

   public static byte[] getPlayerTalk(int npc, byte msgType, String talk, String endBytes, byte type, byte borderStyle, int diffNpc) {
/* 201 */     return getNPCTalk(npc, msgType, talk, endBytes, type, borderStyle, diffNpc, true);
   }

   public static byte[] getNPCTalk(int npc, byte msgType, String talk, String endBytes, byte type, int diffNpc, boolean player) {
/* 205 */     return getNPCTalk(npc, msgType, talk, endBytes, type, (byte)0, diffNpc, true);
   }

   public static byte[] getNPCTalk(int npc, byte msgType, String talk, String endBytes, byte type, byte borderStyle, int diffNpc, boolean player) {
/* 209 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 211 */     mplew.writeShort(SendPacketOpcode.NPC_TALK.getValue());
/* 212 */     mplew.write(player ? 3 : 4);
/* 213 */     mplew.writeInt(npc);
/* 214 */     mplew.write(player ? 1 : 0);
/* 215 */     if (player) {
/* 216 */       mplew.writeInt(0);
     }
/* 218 */     mplew.write(msgType);
/* 219 */     mplew.writeShort((short)type);
/* 220 */     mplew.write(borderStyle);
/* 221 */     if ((type & 0x4) != 0) {
/* 222 */       mplew.writeInt(diffNpc);
     }
/* 224 */     mplew.writeMapleAsciiString(talk);
/* 225 */     mplew.write(HexTool.getByteArrayFromHexString(endBytes));
/* 226 */     mplew.writeInt(0);
/* 227 */     mplew.write(0);
/* 228 */     return mplew.getPacket();
   }


   public static byte[] OnSay(int nSpeakerTypeID, int nSpeakerTemplateID, boolean b1, int n2, int subtype, byte bParam, boolean bPrev, boolean bNext, String talk) {
/* 233 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
/* 234 */     mplew.writeShort(SendPacketOpcode.NPC_TALK.getValue());

/* 236 */     writeTalkData(mplew, (byte)nSpeakerTypeID, nSpeakerTemplateID, b1, n2, (byte) NPCTalkOP.SM_SAY.getValue(), bParam, (byte)1);
/* 237 */     if ((bParam & 0x4) != 0) {
/* 238 */       mplew.writeInt(subtype);
     }
/* 240 */     mplew.writeMapleAsciiString(talk);
/* 241 */     mplew.writeBool(bPrev);
/* 242 */     mplew.writeBool(bNext);
/* 243 */     mplew.writeInt(0);

/* 245 */     return mplew.getPacket();
   }

   public static byte[] OnSayImage(int nSpeakerTypeID, int nSpeakerTemplateID, byte bParam, List<String> asPath) {
/* 249 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
/* 250 */     mplew.writeShort(SendPacketOpcode.NPC_TALK.getValue());
/* 251 */     mplew.write(nSpeakerTypeID);
/* 252 */     mplew.writeInt(nSpeakerTemplateID);
/* 253 */     mplew.writeShort(MapleEnumClass.ScriptMessageType.SAYIMAGE.getMsgType());
/* 254 */     mplew.write(bParam);
/* 255 */     mplew.write(asPath.size());
/* 256 */     for (String sPath : asPath) {
/* 257 */       mplew.writeMapleAsciiString(sPath);
     }
/* 259 */     return mplew.getPacket();
   }

   public static byte[] OnAskYesNo(int nSpeakerTypeID, int nSpeakerTemplateID, byte bParam, String sText) {
/* 263 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
/* 264 */     mplew.writeShort(SendPacketOpcode.NPC_TALK.getValue());
/* 265 */     mplew.write(nSpeakerTypeID);
/* 266 */     mplew.writeInt(nSpeakerTemplateID);
/* 267 */     mplew.writeShort(MapleEnumClass.ScriptMessageType.ASKYESNO.getMsgType());
/* 268 */     mplew.write(bParam);
/* 269 */     mplew.writeMapleAsciiString(sText);
/* 270 */     return mplew.getPacket();
   }

   public static byte[] OnAskAccept(int nSpeakerTypeID, int nSpeakerTemplateID, int subtype, byte bParam, String talk) {
/* 274 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 276 */     writeTalkData(mplew, (byte)nSpeakerTypeID, nSpeakerTemplateID, (byte) NPCTalkOP.SM_ASKACCEPT.getValue(), bParam, (byte)1);
/* 277 */     if ((bParam & 0x4) != 0) {
/* 278 */       mplew.writeInt(subtype);
     }
/* 280 */     mplew.writeMapleAsciiString(talk);

/* 282 */     return mplew.getPacket();
   }

   public static byte[] OnAskText(int nSpeakerTypeID, int nSpeakerTemplateID, int subtype, byte bParam, short nLenMin, short nLenMax, String sMsg, String sMsgDefault) {
/* 286 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 288 */     writeTalkData(mplew, (byte)nSpeakerTypeID, nSpeakerTemplateID, (byte) NPCTalkOP.SM_ASKTEXT.getValue(), bParam, (byte)1);
/* 289 */     if ((bParam & 0x4) != 0) {
/* 290 */       mplew.writeInt(subtype);
     }
/* 292 */     mplew.writeMapleAsciiString(sMsg);
/* 293 */     mplew.writeMapleAsciiString(sMsgDefault);
/* 294 */     mplew.writeShort(nLenMin);
/* 295 */     mplew.writeShort(nLenMax);

/* 297 */     return mplew.getPacket();
   }

   public static byte[] OnAskBoxText(int nSpeakerTypeID, int nSpeakerTemplateID, int subtype, byte bParam, short nCol, short nLine, String sMsg, String sMsgDefault) {
/* 301 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 303 */     writeTalkData(mplew, (byte)nSpeakerTypeID, nSpeakerTemplateID, (byte) NPCTalkOP.SM_ASKBOXTEXT.getValue(), bParam, (byte)0);
/* 304 */     if ((bParam & 0x4) != 0) {
/* 305 */       mplew.writeInt(subtype);
     }
/* 307 */     mplew.writeMapleAsciiString(sMsg);
/* 308 */     mplew.writeMapleAsciiString(sMsgDefault);
/* 309 */     mplew.writeShort(nCol);
/* 310 */     mplew.writeShort(nLine);

/* 312 */     return mplew.getPacket();
   }

   public static byte[] OnAskNumber(int nSpeakerTypeID, int nSpeakerTemplateID, int subtype, byte bParam, int nDef, int nMin, int nMax, String sMsg) {
/* 316 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 318 */     writeTalkData(mplew, (byte)nSpeakerTypeID, nSpeakerTemplateID, (byte) NPCTalkOP.SM_ASKNUMBER.getValue(), bParam, (byte)1);
/* 319 */     mplew.writeMapleAsciiString(sMsg);
/* 320 */     mplew.writeInt(nDef);
/* 321 */     mplew.writeInt(nMin);
/* 322 */     mplew.writeInt(nMax);

/* 324 */     return mplew.getPacket();
   }

   public static byte[] OnAskMenu(byte nSpeakerTypeID, int nSpeakerTemplateID, int subtype, byte bParam, String talk) {
/* 328 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 330 */     writeTalkData(mplew, nSpeakerTypeID, nSpeakerTemplateID, (byte) NPCTalkOP.SM_ASKMENU.getValue(), bParam, (byte)1);
/* 331 */     if ((bParam & 0x4) != 0) {
/* 332 */       mplew.writeInt(subtype);
     }
/* 334 */     mplew.writeMapleAsciiString(talk);

/* 336 */     return mplew.getPacket();
   }

   public static byte[] OnAskAvatar(int nSpeakerTypeID, int nSpeakerTemplateID, String sMsg, int[] anCanadite) {
/* 340 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
/* 341 */     mplew.writeShort(SendPacketOpcode.NPC_TALK.getValue());
/* 342 */     mplew.write(nSpeakerTypeID);
/* 343 */     mplew.writeInt(nSpeakerTemplateID);
/* 344 */     mplew.writeShort(MapleEnumClass.ScriptMessageType.ASKAVATAR.getMsgType());
/* 345 */     mplew.write(0);
/* 346 */     mplew.writeMapleAsciiString(sMsg);
/* 347 */     mplew.write(anCanadite.length);
/* 348 */     for (int nCanadite : anCanadite) {
/* 349 */       mplew.writeInt(nCanadite);
     }
/* 351 */     return mplew.getPacket();
   }

   public static byte[] OnAskAvatar(byte nSpeakerTypeID, int nSpeakerTemplateID, int n3, boolean bl2, boolean bl3, int[] anCanadite, String string) {
/* 355 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 357 */     writeTalkData(mplew, nSpeakerTypeID, nSpeakerTemplateID, (byte) NPCTalkOP.SM_ASKAVATAREX.getValue(), (byte)0, (byte)0);
/* 358 */     mplew.writeBool(bl2);
/* 359 */     mplew.writeBool(bl3);
/* 360 */     mplew.writeMapleAsciiString(string);
/* 361 */     mplew.write(anCanadite.length);
/* 362 */     for (int nCanadite : anCanadite) {
/* 363 */       mplew.writeInt(nCanadite);
     }
/* 365 */     mplew.write(0);
/* 366 */     mplew.writeInt(n3);

/* 368 */     return mplew.getPacket();
   }

   public static byte[] OnAskAndroid(byte by2, int n2, int n3, int[] arrn, String string) {
/* 372 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 374 */     writeTalkData(mplew, by2, n2, (byte) NPCTalkOP.SM_ASKANDROID.getValue(), (byte)0, (byte)0);
/* 375 */     mplew.writeMapleAsciiString(string);
/* 376 */     mplew.write(arrn.length);
/* 377 */     for (int i2 = 0; i2 < arrn.length; i2++) {
/* 378 */       mplew.writeInt(arrn[i2]);
     }
/* 380 */     mplew.writeInt(n3);

/* 382 */     return mplew.getPacket();
   }

   public static byte[] OnAskMembershopAvatar(int nSpeakerTypeID, int nSpeakerTemplateID, String sMsg, int[] aCanadite) {
/* 386 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
/* 387 */     mplew.writeShort(SendPacketOpcode.NPC_TALK.getValue());
/* 388 */     mplew.write(nSpeakerTypeID);
/* 389 */     mplew.writeInt(nSpeakerTemplateID);
/* 390 */     mplew.writeShort(MapleEnumClass.ScriptMessageType.ASKMEMBERSHOPAVATAR.getMsgType());
/* 391 */     mplew.write(0);
/* 392 */     mplew.writeMapleAsciiString(sMsg);
/* 393 */     mplew.write(aCanadite.length);
/* 394 */     for (int nCanadite : aCanadite) {
/* 395 */       mplew.writeInt(nCanadite);
     }
/* 397 */     return mplew.getPacket();
   }

   public static byte[] OnAskPet(byte by2, int n2, List<MaplePet> apPet, String string) {
/* 401 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 403 */     writeTalkData(mplew, by2, n2, (byte) NPCTalkOP.SM_ASKPET.getValue(), (byte)0, (byte)0);
/* 404 */     mplew.writeMapleAsciiString(string);
/* 405 */     mplew.write(apPet.size());
/* 406 */     for (MaplePet pPet : apPet) {
/* 407 */       if (pPet != null) {
/* 408 */         mplew.writeLong(pPet.getUniqueId());
/* 409 */         mplew.write(pPet.getSummonedValue());
       }
     }
/* 412 */     return mplew.getPacket();
   }

   public static byte[] OnAskPet(int nSpeakerTypeID, int nSpeakerTemplateID, String sMsg, List<MaplePet> apPet) {
/* 416 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
/* 417 */     mplew.writeShort(SendPacketOpcode.NPC_TALK.getValue());
/* 418 */     mplew.write(nSpeakerTypeID);
/* 419 */     mplew.writeInt(nSpeakerTemplateID);
/* 420 */     mplew.writeShort(MapleEnumClass.ScriptMessageType.ASKPET.getMsgType());
/* 421 */     mplew.write(0);
/* 422 */     mplew.writeMapleAsciiString(sMsg);
/* 423 */     mplew.write(apPet.size());
/* 424 */     for (MaplePet pPet : apPet) {
/* 425 */       if (pPet != null) {
/* 426 */         mplew.writeLong(pPet.getUniqueId());
/* 427 */         mplew.write(pPet.getSummonedValue());
       }
     }
/* 430 */     return mplew.getPacket();
   }

   public static byte[] OnAskPetAll(int nSpeakerTypeID, int nSpeakerTemplateID, String sMsg, List<MaplePet> apPet, boolean bExceptionExist) {
/* 434 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
/* 435 */     mplew.writeShort(SendPacketOpcode.NPC_TALK.getValue());
/* 436 */     mplew.write(nSpeakerTypeID);
/* 437 */     mplew.writeInt(nSpeakerTemplateID);
/* 438 */     mplew.writeShort(MapleEnumClass.ScriptMessageType.ASKPETALL.getMsgType());
/* 439 */     mplew.write(0);
/* 440 */     mplew.writeMapleAsciiString(sMsg);
/* 441 */     mplew.write(apPet.size());
/* 442 */     mplew.writeBool(bExceptionExist);
/* 443 */     for (MaplePet pPet : apPet) {
/* 444 */       if (pPet != null) {
/* 445 */         mplew.writeLong(pPet.getUniqueId());
/* 446 */         mplew.write(pPet.getSummonedValue());
       }
     }
/* 449 */     return mplew.getPacket();
   }

   public static byte[] OnAskQuiz(int nSpeakerTypeID, int nSpeakerTemplateID, int nResCode, String sTitle, String sProblemText, String sHintText, int nMinInput, int nMaxInput, int tRemainInitialQuiz) {
/* 453 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
/* 454 */     mplew.writeShort(SendPacketOpcode.NPC_TALK.getValue());
/* 455 */     mplew.write(nSpeakerTypeID);
/* 456 */     mplew.writeInt(nSpeakerTemplateID);
/* 457 */     mplew.writeShort(MapleEnumClass.ScriptMessageType.ASKQUIZ.getMsgType());
/* 458 */     mplew.write(0);
/* 459 */     mplew.write(nResCode);
/* 460 */     if (nResCode == 0) {
/* 461 */       mplew.writeMapleAsciiString(sTitle);
/* 462 */       mplew.writeMapleAsciiString(sProblemText);
/* 463 */       mplew.writeMapleAsciiString(sHintText);
/* 464 */       mplew.writeShort(nMinInput);
/* 465 */       mplew.writeShort(nMaxInput);
/* 466 */       mplew.writeInt(tRemainInitialQuiz);
     }
/* 468 */     return mplew.getPacket();
   }

   public static byte[] OnAskSpeedQuiz(int nSpeakerTypeID, int nSpeakerTemplateID, int nResCode, int nType, int dwAnswer, int nCorrect, int nRemain, int tRemainInitialQuiz) {
/* 472 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
/* 473 */     mplew.writeShort(SendPacketOpcode.NPC_TALK.getValue());
/* 474 */     mplew.write(nSpeakerTypeID);
/* 475 */     mplew.writeInt(nSpeakerTemplateID);
/* 476 */     mplew.writeShort(MapleEnumClass.ScriptMessageType.ASKSPEEDQUIZ.getMsgType());
/* 477 */     mplew.write(0);
/* 478 */     mplew.write(nResCode);
/* 479 */     if (nResCode == 0) {
/* 480 */       mplew.writeInt(nType);
/* 481 */       mplew.writeInt(dwAnswer);
/* 482 */       mplew.writeInt(nCorrect);
/* 483 */       mplew.writeInt(nRemain);
/* 484 */       mplew.writeInt(tRemainInitialQuiz);
     }
/* 486 */     return mplew.getPacket();
   }

   public static byte[] OnAskSlideMenu(int nSpeakerTypeID, int nSpeakerTemplateID, boolean bSlideDlgEX, int nIndex, String sMsg) {
/* 490 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
/* 491 */     mplew.writeShort(SendPacketOpcode.NPC_TALK.getValue());
/* 492 */     mplew.write(nSpeakerTypeID);
/* 493 */     mplew.writeInt(nSpeakerTemplateID);
/* 494 */     mplew.writeShort(MapleEnumClass.ScriptMessageType.ASKSLIDEMENU.getMsgType());
/* 495 */     mplew.write(0);
/* 496 */     mplew.writeInt(bSlideDlgEX ? 1 : 0);
/* 497 */     mplew.writeInt(nIndex);
/* 498 */     mplew.writeMapleAsciiString(sMsg);
/* 499 */     return mplew.getPacket();
   }

   public static byte[] OnAskSelectMenu(byte nSpeakerTypeID, int idd, int subtype, String[] arrstring) {
/* 503 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 505 */     writeTalkData(mplew, nSpeakerTypeID, 0, true, idd, (byte) NPCTalkOP.SM_ASKSELECTMENU.getValue(), (byte)0, (byte)0);
/* 506 */     mplew.writeInt(subtype);
/* 507 */     mplew.writeInt(0);
/* 508 */     mplew.writeInt((arrstring != null) ? arrstring.length : 0);
/* 509 */     for (int i2 = 0; arrstring != null && i2 < arrstring.length; i2++) {
/* 510 */       mplew.writeMapleAsciiString(arrstring[i2]);
     }
/* 512 */     return mplew.getPacket();
   }

   public static byte[] getSlideMenu(int nSpeakerTypeID, int npcid, int type, int lasticon, String sel) {
/* 516 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 518 */     mplew.writeShort(SendPacketOpcode.NPC_TALK.getValue());
/* 519 */     mplew.write(nSpeakerTypeID);
/* 520 */     mplew.writeInt(npcid);
/* 521 */     mplew.write(0);
/* 522 */     mplew.writeShort(19);
/* 523 */     mplew.write(0);
/* 524 */     mplew.write(0);
/* 525 */     mplew.writeInt(type);
/* 526 */     mplew.writeInt((type == 0) ? lasticon : 0);
/* 527 */     mplew.writeMapleAsciiString(sel);

/* 529 */     return mplew.getPacket();
   }


   public static byte[] getMapSelection(int npcid, byte msgType, String sel) {
/* 534 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 535 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 537 */     mplew.writeShort(SendPacketOpcode.NPC_TALK.getValue());
/* 538 */     mplew.write(4);
/* 539 */     mplew.writeInt(npcid);
/* 540 */     mplew.write(0);
/* 541 */     mplew.writeShort((short)msgType);
/* 542 */     mplew.writeShort(0);
/* 543 */     mplew.writeInt((npcid == 3000012) ? 5 : ((npcid == 9010000) ? 3 : ((npcid == 2083006) ? 1 : 0)));
/* 544 */     mplew.writeInt((npcid == 9010022) ? 1 : 0);
/* 545 */     mplew.writeMapleAsciiString(sel);

/* 547 */     return mplew.getPacket();
   }

   public static byte[] getNPCTalkStyle(MapleCharacter player, int npc, String talk, int[] styles, int card, boolean android, boolean isSecond) {
/* 551 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 553 */     mplew.writeShort(SendPacketOpcode.NPC_TALK.getValue());
/* 554 */     mplew.write(4);
/* 555 */     mplew.writeInt(npc);
/* 556 */     mplew.write(0);
/* 557 */     mplew.writeShort(android ? 11 : 10);
/* 558 */     mplew.writeShort(0);
/* 559 */     if (!android) {
/* 560 */       mplew.writeShort(isSecond ? 1 : 0);
     }
/* 562 */     mplew.writeMapleAsciiString(talk);
/* 563 */     if (!android) {
/* 564 */       mplew.writeInt(player.getHair());
/* 565 */       mplew.writeInt(player.getFace());
/* 566 */       mplew.writeInt(card);
     }
/* 568 */     mplew.write(styles.length);
/* 569 */     for (int style : styles) {
/* 570 */       mplew.writeInt(style);
     }
/* 572 */     mplew.write(0);
/* 573 */     mplew.writeInt(card);

/* 575 */     return mplew.getPacket();
   }

   public static byte[] getNPCTalkNum(int npc, byte msgType, String talk, int def, int min, int max) {
/* 579 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 581 */     mplew.writeShort(SendPacketOpcode.NPC_TALK.getValue());
/* 582 */     mplew.write(4);
/* 583 */     mplew.writeInt(npc);
/* 584 */     mplew.write(0);
/* 585 */     mplew.writeShort((short)msgType);
/* 586 */     mplew.writeShort(0);
/* 587 */     mplew.writeMapleAsciiString(talk);
/* 588 */     mplew.writeInt(def);
/* 589 */     mplew.writeInt(min);
/* 590 */     mplew.writeInt(max);

/* 592 */     return mplew.getPacket();
   }

   public static byte[] getNPCTalkText(int npc, byte msgType, String talk) {
/* 596 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 598 */     mplew.writeShort(SendPacketOpcode.NPC_TALK.getValue());
/* 599 */     mplew.write(4);
/* 600 */     mplew.writeInt(npc);
/* 601 */     mplew.write(0);
/* 602 */     mplew.writeShort((short)msgType);
/* 603 */     mplew.writeShort(0);
/* 604 */     mplew.writeMapleAsciiString(talk);
/* 605 */     mplew.writeInt(0);
/* 606 */     mplew.writeInt(0);

/* 608 */     return mplew.getPacket();
   }

   public static byte[] getNPCTalkText(byte type, byte mode, int npcid) {
/* 612 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 614 */     mplew.writeShort(SendPacketOpcode.NPC_TALK.getValue());
/* 615 */     mplew.write(MapleEnumClass.ScriptMessageType.ASKTEXT.getMsgType());
/* 616 */     mplew.writeInt(0);
/* 617 */     mplew.write(1);
/* 618 */     mplew.writeInt(npcid);
/* 619 */     mplew.writeShort(24);
/* 620 */     mplew.write(1);
/* 621 */     mplew.write(0);
/* 622 */     mplew.writeShort(1);
/* 623 */     mplew.writeLong(0L);
/* 624 */     mplew.writeShort(0);

/* 626 */     return mplew.getPacket();
   }







   public static byte[] getEvanTutorial(String data) {
/* 636 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 637 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 639 */     mplew.writeShort(SendPacketOpcode.NPC_TALK.getValue());
/* 640 */     mplew.write(4);
/* 641 */     mplew.writeInt(0);
/* 642 */     mplew.write(0);
/* 643 */     mplew.writeShort(2);
/* 644 */     mplew.writeShort(1);
/* 645 */     mplew.write(1);
/* 646 */     mplew.writeMapleAsciiString(data);

/* 648 */     return mplew.getPacket();
   }

   public static byte[] getAskMIXHair(int npc, String data) {
/* 652 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 654 */     writeTalkData(mplew, (byte)3, npc, (byte) NPCTalkOP.SM_ASKMIXHAIR.getValue(), (byte)0, (byte)0);
/* 655 */     mplew.writeInt(0);
/* 656 */     mplew.write(0);
/* 657 */     mplew.write(0);
/* 658 */     mplew.writeShort(1);
/* 659 */     mplew.writeMapleAsciiString(data);
/* 660 */     int n3 = 8;
/* 661 */     mplew.write(n3);
/* 662 */     for (int i2 = 0; i2 < n3; i2++) {
/* 663 */       mplew.writeInt(i2);
     }
/* 665 */     mplew.writeInt(0);
/* 666 */     return mplew.getPacket();
   }

   public static byte[] getAskMIXHairNew(int n2, String string) {
/* 670 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 672 */     writeTalkData(mplew, (byte)3, n2, (byte) NPCTalkOP.SM_ASKMIXHAIR_NEW.getValue(), (byte)0, (byte)0);
/* 673 */     mplew.writeInt(0);
/* 674 */     mplew.write(0);
/* 675 */     mplew.write(0);
/* 676 */     mplew.write(2);
/* 677 */     mplew.writeMapleAsciiString(string);
/* 678 */     int n3 = 3;
/* 679 */     mplew.write(n3);
/* 680 */     if (n3 == 3) {
/* 681 */       mplew.writeInt(1);
/* 682 */       mplew.writeInt(1);
/* 683 */       mplew.writeInt(1);
     } else {
/* 685 */       mplew.writeInt(0);
/* 686 */       mplew.writeInt(0);
/* 687 */       mplew.writeInt(0);
/* 688 */       mplew.writeInt(0);
/* 689 */       mplew.writeInt(0);
/* 690 */       mplew.writeInt(0);
     }
/* 692 */     return mplew.getPacket();
   }

   public static byte[] getAskCustomMIXHair(int n2, String string) {
/* 696 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 698 */     writeTalkData(mplew, (byte)3, n2, (byte) NPCTalkOP.SM_ASKCUSTOMMIXHAIR.getValue(), (byte)0, (byte)0);
/* 699 */     mplew.writeInt(0);
/* 700 */     mplew.write(0);
/* 701 */     mplew.writeInt(0);
/* 702 */     mplew.writeInt(0);
/* 703 */     mplew.writeMapleAsciiString(string);

/* 705 */     return mplew.getPacket();
   }

   public static void writeTalkData(MaplePacketLittleEndianWriter mplew, byte nSpeakerTypeID, int nSpeakerTemplateID, byte optype, byte bParam, byte by5) {
/* 709 */     writeTalkData(mplew, nSpeakerTypeID, nSpeakerTemplateID, false, 0, optype, bParam, by5);
   }

   public static void writeTalkData(MaplePacketLittleEndianWriter mplew, byte nSpeakerTypeID, int nSpeakerTemplateID, boolean bl2, int n3, byte optype, byte bParam, byte by5) {
/* 713 */     mplew.writeShort(SendPacketOpcode.NPC_TALK.getValue());
/* 714 */     mplew.write(nSpeakerTypeID);
/* 715 */     mplew.writeInt(nSpeakerTemplateID);
/* 716 */     mplew.writeBool(bl2);
/* 717 */     if (bl2) {
/* 718 */       mplew.writeInt(n3);
     }
/* 720 */     mplew.write(optype);
/* 721 */     mplew.writeShort((short)bParam);
/* 722 */     mplew.write(by5);
   }




/*
 * 打开1个商店
 */
public static byte[] getNPCShop(int shopId, MapleShop shop, MapleClient c) {
    MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

    mplew.writeShort(SendPacketOpcode.OPEN_NPC_SHOP.getValue());
    mplew.write(0);
    PacketHelper.addShopInfo(mplew, shop, c, shopId);

    return mplew.getPacket();
}






































   public static byte[] confirmShopTransaction(MapleShopResponse code, MapleShop shop, MapleClient c, int indexBought, int itemid) {
/* 777 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 779 */     mplew.writeShort(SendPacketOpcode.CONFIRM_SHOP_TRANSACTION.getValue());
/* 780 */     mplew.write(code.getValue());
/* 781 */     switch (code) {

       case 购买道具完成:
/* 784 */         mplew.write((indexBought >= 0) ? 1 : 0);
/* 785 */         if (indexBought >= 0) {
/* 786 */           mplew.writeInt(indexBought);
         } else {

/* 789 */           mplew.writeInt(itemid);
/* 790 */           mplew.writeInt(100000);
/* 791 */           mplew.writeInt(0);
         }



       case 卖出道具完成:
/* 797 */         PacketHelper.addShopInfo(mplew, shop, c, shop.getNpcId());











       case 背包空间不够:
       case 充值飞镖完成:
       case 充值金币不够:
/* 812 */         return mplew.getPacket();
       case 购买回购出错:
         mplew.write(0);
         mplew.write(0);
     }
     System.err.println("未知商店买卖操作: " + code);
return null;
   }
public static byte[] takeOutStorage(short slots, MapleInventoryType type, Collection<Item> items) {
/* 819 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 820 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 822 */     mplew.writeShort(SendPacketOpcode.OPEN_STORAGE.getValue());
/* 823 */     mplew.write(9);
/* 824 */     mplew.write(slots);
/* 825 */     mplew.writeLong(type.getBitfieldEncoding());
/* 826 */     mplew.write(items.size());
/* 827 */     for (Item item : items) {
/* 828 */       PacketHelper.addItemInfo(mplew, item);
     }

/* 831 */     return mplew.getPacket();
   }









   public static byte[] getStorageError(byte op) {
/* 843 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 844 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 846 */     mplew.writeShort(SendPacketOpcode.OPEN_STORAGE.getValue());
/* 847 */     mplew.write(op);

/* 849 */     return mplew.getPacket();
   }




   public static byte[] storeStorage(short slots, MapleInventoryType type, Collection<Item> items) {
/* 856 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 857 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 859 */     mplew.writeShort(SendPacketOpcode.OPEN_STORAGE.getValue());
/* 860 */     mplew.write(13);
/* 861 */     mplew.write(slots);
/* 862 */     mplew.writeLong(type.getBitfieldEncoding());
/* 863 */     mplew.write(items.size());
/* 864 */     for (Item item : items) {
/* 865 */       PacketHelper.addItemInfo(mplew, item);
     }

/* 868 */     return mplew.getPacket();
   }




   public static byte[] arrangeStorage(short slots, Collection<Item> items, boolean changed) {
/* 875 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 876 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 878 */     mplew.writeShort(SendPacketOpcode.OPEN_STORAGE.getValue());
/* 879 */     mplew.write(15);
/* 880 */     mplew.write(slots);
/* 881 */     mplew.writeLong(124L);








/* 890 */     mplew.write(items.size());
/* 891 */     for (Item item : items) {
/* 892 */       PacketHelper.addItemInfo(mplew, item);
     }
/* 894 */     mplew.writeInt(0);

/* 896 */     return mplew.getPacket();
   }




   public static byte[] mesoStorage(short slots, long meso) {
/* 903 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 905 */     mplew.writeShort(SendPacketOpcode.OPEN_STORAGE.getValue());
/* 906 */     mplew.write(19);
/* 907 */     mplew.write(slots);
/* 908 */     mplew.writeLong(2L);
/* 909 */     mplew.writeLong(meso);

/* 911 */     return mplew.getPacket();
   }




   public static byte[] getStorage(int npcId, short slots, Collection<Item> items, long meso) {
/* 918 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 920 */     mplew.writeShort(SendPacketOpcode.OPEN_STORAGE.getValue());
/* 921 */     mplew.write(22);
/* 922 */     mplew.writeInt(npcId);
/* 923 */     mplew.write(slots);
/* 924 */     mplew.writeLong(126L);
/* 925 */     mplew.writeLong(meso);








/* 934 */     mplew.write(items.size());
/* 935 */     for (Item item : items) {
/* 936 */       PacketHelper.addItemInfo(mplew, item);
     }
/* 938 */     mplew.writeInt(0);

/* 940 */     return mplew.getPacket();
   }

   public static byte[] setNPCSpecialAction(int npcoid, String string) {
/* 944 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 946 */     mplew.writeShort(SendPacketOpcode.NPC_SPECIAL_ACTION.getValue());
/* 947 */     mplew.writeInt(npcoid);
/* 948 */     mplew.writeMapleAsciiString(string);
/* 949 */     mplew.writeInt(0);
/* 950 */     mplew.write(0);

/* 952 */     return mplew.getPacket();
   }

   public static byte[] updateNPCSpecialAction(int npcoid, int value, int x, int y) {
/* 956 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 958 */     mplew.writeShort(SendPacketOpcode.FORCE_MOVE_BY_SCRIPT.getValue());
/* 959 */     mplew.writeInt(npcoid);
/* 960 */     mplew.writeInt(value);
/* 961 */     mplew.writeInt(x);
/* 962 */     mplew.writeInt(y);

/* 964 */     return mplew.getPacket();
   }

   public static byte[] moveNpc(MaplePacketLittleEndianWriter mplew) {
/* 968 */     mplew.writeInt(0);
/* 969 */     mplew.writePos(new Point(0, 0));
/* 970 */     mplew.writeInt(0);
/* 971 */     PacketHelper.serializeMovementList(mplew, new ArrayList<>());
/* 972 */     return mplew.getPacket();
   }
 }


/* Location:              C:\PGX\Server.jar!\tools\packet\NPCPacket.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */